# The American Viewer: Political Consequences of Entertainment Media
# Eunji Kim and Shawn Patterson Jr 
# American Political Science Review 
# Replication File [Appendix I Table I3]

library(foreign)
library(lfe)
library(haven)


tablei3 <- read.csv("appendix_tablei3_censored.csv")

#  Column (1) Primary Election Donation for Trump OLS 

ols_pri <- felm(log_primary_donation~  RTG_9PM_Nov_May + romneyshare12_new + 
                  log(population_04 +1) +
                  log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04  +
                  collegeP_04 + foreignBP_04 + unemR_04   + samesex_census  + religion_allP +
                  log(avg_outflow_movers + 1) + log(avg_inflow_movers + 1 ) + pop_density.x   | 
                  STATE  | 0 | 0 , 
                data = tablei3, weights=tablei3$sum_CNTYTVHH) 

stargazer(ols_pri, no.space=TRUE,type="text" )

#  Column (2) Primary Election Donation for Trump 2SLS

iv_pri<- felm(log_primary_donation~  romneyshare12_new + 
                log(population_04 +1) +
                log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04  +
                collegeP_04 + foreignBP_04 + unemR_04    +  samesex_census  + religion_allP +
                log(avg_outflow_movers + 1) + log(avg_inflow_movers + 1 ) + pop_density.x  | 
                STATE  | (RTG_9PM_Nov_May  ~ RTG_8PM_Nov_May)| 0 , 
              data = tablei3, weights=tablei3$sum_CNTYTVHH) 
stargazer(iv_pri,  no.space=TRUE,type="text")


#  Column (3) General Election Donation for Trump OLS 

ols_prez <- felm(log_general_donation ~ RTG_9PM_Nov_May + romneyshare12_new + 
                   log(population_04 +1) +
                   log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04  +
                   collegeP_04 + foreignBP_04 + unemR_04   + samesex_census  + religion_allP +
                   log(avg_outflow_movers + 1) + log(avg_inflow_movers + 1 ) + pop_density.x   | 
                   STATE  | 0 | 0 ,  data = tablei3, weights=tablei3$sum_CNTYTVHH) 

stargazer(ols_prez,  no.space=TRUE,type="text")


#  Column (4) General Election Donation for Trump 2SLS

iv_prez<- felm(log_general_donation~  romneyshare12_new + 
                 log(population_04 +1) +
                 log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04  +
                 collegeP_04 + foreignBP_04 + unemR_04    +  samesex_census  + religion_allP +
                 log(avg_outflow_movers + 1) + log(avg_inflow_movers + 1 ) + pop_density.x  | 
                 STATE  | (RTG_9PM_Nov_May  ~ RTG_8PM_Nov_May)| 0 , 
               data = tablei3, weights=tablei3$sum_CNTYTVHH) 

stargazer(iv_prez, no.space=TRUE,type="text")

## full results, columns 1 to 4

stargazer(ols_pri,  iv_pri,  ols_prez, iv_prez,  
          star.cutoffs = c(.05,.01,.001),
          title="No Apprentice Effects on Campaign Donation for Trump",
          dep.var.caption = "",
          label = "tab2",
          dep.var.labels=c('Primary - OLS',  'Primary - IV', 
                           'General - OLS', 'General - IV'),
          omit.stat=c("adj.rsq","LL","ser","f"),
          keep.stat = c("n"),
          no.space=TRUE,
          omit = c('STATE'),
          star.char = c("*", "**", "***"), 
          notes = c("* p<0.05; ** p<0.01; *** p<0.001"), 
          notes.append = F,
          notes.align="l",
          digits=3,
          type="text",
          align = TRUE)